﻿using System.IO;
using System.Web;

using WebImageResizer.Utils;

namespace WebImageResizer.ImageProviders
{
	/// <summary>
	/// File System Image Provider
	/// Read data from darddrive
	/// </summary>
	internal class FileSystemImageProvider : IImageProvider
	{
		#region IImageProvider Members

		public byte[] GetImageData(string src)
		{
			if (string.IsNullOrEmpty(src))
			{
				return null;
			}

			if (HttpContext.Current.IsNull())
			{
				return FileSystemHelpers.FileExists(src) ? File.ReadAllBytes(src) : null;
			}

			string filePath = HttpContext.Current.Server.MapPath(src);
			return FileSystemHelpers.FileExists(filePath) ? File.ReadAllBytes(filePath) : null;
		}

		#endregion
	}
}